package cn.wonderland.user.dto;

import cn.wonderland.basic.util.MD5Utils;
import cn.wonderland.basic.util.StrUtils;
import cn.wonderland.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class WechatBinderDto {

    @NotBlank(message = "电话不能为空！")
    private String phone;
    @NotBlank(message = "验证码不能为空！")
    private String verifyCode;
    @NotBlank(message = "accessToken不能为空！")
    private String accessToken;
    @NotBlank(message = "openId不能为空！")
    private String openId;

    public User getUser() {
        // 盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 密码
        String pwd = MD5Utils.encrypByMd5(salt + "1");

        return User.
                builder()
                .phone(this.phone)
                .state(1)
                .createtime(new Date())
                .password(pwd)
                .salt(salt)
                .username(this.phone)
                .build();
    }

}
